<html>
<head>
<title>Test</title>
<link rel="stylesheet" href="style.css" type="text\css">
</head>
<body>
<?php 
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "fei_hackathon";

$con_db=mysqli_connect($dbhost,$dbuser,$dbpass,$dbname) or die ('Error connecting with the server');

// Check connection
if (mysqli_connect_errno()) {
	echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

//get the total number of rows and set it to an array
$result = mysqli_query($con_db,"SELECT COUNT(*) FROM memetable");

	if($row = mysqli_fetch_array($result)) {
		$maxEntries = $row[0];
	}
	
	$idNum = $_GET['idNumber'];
?>
<div class="mainBody">
	<a href="./CIEgag.php?idNumber=<?php 
		if($idNum==1)
			echo $maxEntries;
		else{
			echo $idNum-1;
		}
		 ?>">
	<div class="leftBody">
		<table style="width:100%; height:100%;"><tr><td>
		
		
		
		<?php 
			if(!empty($idNum))
			{
				$result = mysqli_query($con_db,"SELECT source, memeName FROM memetable WHERE id=$idNum");
				$imageURL="";
				if($row = mysqli_fetch_array($result)) {
					$imageURL = $row[0];
					$title = $row[1];
				}
			}
		?>
		<img src="./images/left.png" id="navImage">
		</td></tr></table>	
	</div></a>
	<div class="singleEntry">
		<h1><?php echo $title; ?></h1>	
		<div class="image">
			<img src="<?php echo $imageURL; ?>" id="imageEntry" alt="test">
		</div>
		<div class="contents">
			<img src="./images/thumbs_up.jpg" id="thumbs">
			<br>
			<img src="./images/thumbs_down.jpg" id="thumbs">
			<br><br><br>
			NUM
			<br>
		</div>
	</div>
	<a href="./CIEgag.php?idNumber=<?php 
		if($idNum == intval($maxEntries)){
			$idNum=1;
			echo $idNum;
		}
		else{
		echo $idNum+1;} ?>">
	<div class="rightBody">
		<table style="width:100%; height:100%;"><tr><td>
		
		
		<img src="./images/right.png" id="navImage">
		</td></tr></table>	
	</div></a>
	<br style="clear: left;" />
</div>

<?php mysqli_close($con_db);?>
</body>
</html>
